package kr.pfg.applications.captureyourscreen.clipboard
{
	import flash.desktop.Clipboard;
	import flash.desktop.ClipboardFormats;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import kr.pfg.applications.captureyourscreen.events.CaptureEvent;
	
	public class ClipboardChecker extends Sprite
	{
		public function ClipboardChecker()
		{
			this.init();
		}
		
		private function init():void
		{
			
		}
		
		public function start():void
		{
			this.addEventListener( Event.ENTER_FRAME, this.checkBitmapData );
		}
		
		private function checkBitmapData( e:Event ):void
		{
			if( Clipboard.generalClipboard.hasFormat( ClipboardFormats.BITMAP_FORMAT ) )
			{
				trace( "found bitmapData" );
				var captured:BitmapData = Clipboard.generalClipboard.getData( ClipboardFormats.BITMAP_FORMAT ) as BitmapData;
				this.dispatchEvent( new CaptureEvent( CaptureEvent.CAPTURE_SUCCESS, captured ) );
				Clipboard.generalClipboard.clear();
				
			}
		}
	}
}